<?php
namespace Admin\Controller;

/**
 * 行为控制器
 * @author huajie <banhuajie@163.com>
 */
class FriendurlController extends AdminController {
    public function index(){
        $fri=D('friendurl');
        $where['status']=array('gt',0);
        $res=$fri->where($where)->select();
        dump($fri->getlastsql());
        $this->assign('res',$res);
        $this->display();
    }

    public function add(){
        if(IS_POST){
            $_POST['ctime']=date('Y-m-d h:i:s',time());
            $fri=D('friendurl');
            $res=$fri->create();
            if($res){
                if($fri->add($res)){
                    
                    $this->success('添加成功',U('index'));
                }else{
                    $this->error('添加成功');
                }
            }else{
                $this->error($fri->getError());
            }

        }else{
            $this->display();
        }
        
    }

   public function changeStatus(){
       if(IS_GET){
           $method=$_GET['method'];
           $fri=D('friendurl');
           $id=$_GET['id'];
           switch($method){
               case hide:
                    $res=$fri->where('id='.$id)->setField('status',0);
                    break;
               case show:
                    $res=$fri->where('id='.$id)->setField('status',1);
                    break;
               case del:
                    $res=$fri->where('id='.$id)->setField('status',-1);
                    break;
           }
           if($res){
               $this->success('操作成功');
           }else{
               $this->error('操作失败');
           }
       }else{
           $this->display();
       }
   }
}